import { getCategoryAll } from '@/api/category'
import { categoryList } from '@/utils/constant'

// 商品分类模块
export default {
  namespaced: true,
  state () {
    return {
      // 商品分类列表
      list: categoryList.map(item => ({ name: item }))
    }
  },
  mutations: {
    // 修改商品分类列表
    setList (state, value) {
      state.list = value
    }
  },
  actions: {
    // 获取商品分类列表
    async getList ({ commit }) {
      // 发起请求
      const { result } = await getCategoryAll()
      commit('setList', result)
    }
  }
}
